% this function decompose given matrix Z to eigenvalues&vectors but only
% those corresponds to r largest abs(eigenvalues)
% Z = V*diag(d)*V'  but only for r values...
function [V,d] = eig_r(Z,r)
[Vz,Dz]=eig(Z);
dz=diag(Dz);
[sd Id]=sort(dz,'descend');
Idr = Id(1:r);
d = dz(Idr);
V = Vz(:,Idr);

